package com.thientan.controller

import java.text.SimpleDateFormat

import com.thientan.model.HopDong
import com.thientan.service.InKhachHangService
import com.thientan.utils.Constants
import com.thientan.utils.Utility

class InKhachHangController extends HopDongController{
	InKhachHangService inKhachHangService

	@Override
	public Object getDomainService() {
		return inKhachHangService
	}

	@Override
	protected String getExportFileName(){
		"PhieuThuKhachHang"
	}

	@Override
	protected Map buildExportData(Map exportParams){
		// Collect hopDong infor to export Phieu Thu
		HopDong hopDong = HopDong.get(params["id"])
		String maHd = hopDong ? hopDong.maHd : ""
		String maNv1 = hopDong?.nvBan1?.maNv ?: ""

		// Generate barcode
		String barcodePath = "${realPath}exported${slash}barcode${maHd}.gif"
		Utility.generateBarcode(maHd, barcodePath)

		// Prepare data for export
		[	'data' : [],
			'ngayin' : printedCurrentDay,
			'tenkhachhang' : hopDong?.khachHang.hoTen ?: "",
			'diachi' : hopDong?.khachHang.fullDiaChi ?: "",
			'dienthoai' : hopDong?.khachHang.dienThoai ?: "",
			'doitruong' : hopDong?.nvDoiTruong?.maNv ?: "",
			'nv' : (maNv1 ? maNv1 + " + " : "") + (hopDong?.nvBan2?.maNv ?: ""),
			'conlai' : Utility.moneyFormat(hopDong.giaTri - hopDong.tienTraTruoc),
			'mavachpath' : barcodePath,
			'logopath' : realPath + logoPath
		]
	}
}
